const fs = require("fs");
const path = require("path");
let fileName = process.argv[2];
const filePath = path.join(__dirname, fileName);

let result = fs.statSync(filePath);
if (result.isFile()) {
    fs.unlink(filePath, (err) => {
        if (err) {
            console.log("删除文件失败")
        } else {
            console.log("成功删除文件")
        }
    })
}
function emptyDir(filePath) {
    const files = fs.readdirSync(filePath);
    files.forEach(file => {
        const testPath = `${filePath}/${file}`;
        const stats = fs.statSync(testPath);
        if (stats.isDirectory()) {
            emptyDir(testPath);
        } else {
            fs.unlinkSync(testPath);
        }
    })
    fs.rmdir(filePath, (err) => {
        if (err) {
            console.log(err)
        }
    });
}
if (result.isDirectory()) {
    emptyDir(filePath);
}
